<template>
  <div class="container">
    <el-input
      style="width: 200px; margin-bottom: 5px"
      v-model="pay_code"
      clearable
      placeholder="请输入付款单号"
    >
    </el-input>
    <el-button
      type="primary"
      class="handleSearch"
      icon="el-icon-search"
      @click="handleSearch()"
      >查询
    </el-button>
    <el-table
      max-height="600"
      :data="tableData"
      border
      style="width: 100%"
      empty-text="暂无数据"
    >
      <el-table-column
        prop="serial_code"
        label="付款单号"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="pay_account"
        label="支付账号"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="pay_bank_name"
        label="支付银行"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="receive_account"
        label="收款账号"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="receive_account_name"
        label="收款户名"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="receive_open_bank"
        label="收款银行"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="statusMsg"
        label="状态"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="apply_date_time"
        label="申请时间"
        align="center"
      ></el-table-column>
      <el-table-column label="图片" align="center" min-width="200px">
        <template slot-scope="scope">
          <div class="imgItem" style="display: flex;">
            <template v-for="(item, index) in scope.row.img">
              <el-image
                style="
                  width: 50px;
                  height: 50px;
                  margin-left: 10px;
                  background: #eee;
                  text-align: center;
                  border-radius: 5px;
                  display: block;
                "
                :src="imgHttp + item"
                fit="cover"
                :preview-src-list="[imgHttp + item]"
              >
              </el-image>
            </template>
          </div>
        </template>
      </el-table-column>
      <el-table-column
        prop="remark"
        label="备注"
        align="center"
      ></el-table-column>
      <el-table-column label="操作" width="150" align="center">
        <template slot-scope="scope">
          <el-button
            size="mini"
            icon="el-icon-circle-check"
            type="success"
            v-if="scope.row.status == 0"
            @click="handleEdit(scope, 1)"
            >同意审核</el-button
          >
          <el-button
            size="mini"
            icon="el-icon-circle-close"
            type="danger"
            v-if="scope.row.status == 0"
            @click="handleEdit(scope, 2)"
            >不同意审核</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <pagination
      @page="handleSizeChange"
      @pagesize="handleCurrentChange"
      :pageData="pageData"
    ></pagination>
  </div>
</template>
<script>
import Pagination from "@/components/pagination";
import {
  applyResetOnlinePayBySuccessList,
  checkApplyResetOnlinePayBySuccess
} from "@/api/settlement/settlementList";

export default {
  components: {
    pagination: Pagination
  },
  data() {
    return {
      //页面数据
      tableData: [],
      pay_code: "",
      imgHttp: this.imgHttp,
      //分页
      pageData: {
        pageSizes: [10, 20],
        pageSize: 10,
        page: 1,
        total: null,
        layout: "total, sizes, prev, pager, next, jumper"
      }
    };
  },

  created() {
    //页面数据
    this.getData();
  },
  methods: {
    //页面数据
    getData() {
      let data = {
        limit: this.pageData.pageSize,
        page: this.pageData.page,
        pay_code: this.pay_code
      };

      applyResetOnlinePayBySuccessList(data)
        .then(res => {
          if (res.code == 0) {
            res.data.data.forEach(prop => {
              switch (prop.status) {
                case 0:
                  prop.statusMsg = "未审核";
                  break;
                case 1:
                  prop.statusMsg = "审核通过";
                  break;
                case 2:
                  prop.statusMsg = "审核失败";
                  break;
              }
            });
            this.tableData = res.data.data;
            this.pageData.page = res.data.current_page;
            this.pageData.pagesize = res.data.per_page;
            this.pageData.total = res.data.total;
          }
        })
        .catch(err => {
          console.log(err);
        });
    },

    //审核
    handleEdit(scope, status) {
      let data = {
        id: scope.row.id,
        status
      };
      this.$confirm("是否审核该条信息?", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          checkApplyResetOnlinePayBySuccess(data).then(res => {
            if (res.code == 0) {
              this.getData();
              this.$message({
                type: "success",
                message: res.message || res.msg
              });
            }
          });
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消"
          });
        });
    },
    // 搜索
    handleSearch() {
      this.pageData.page = 1;
      this.pageData.total = null;
      this.getData();
    },
    //每页多少条
    handleCurrentChange(val) {
      this.pageData.page = 1;
      this.pageData.pageSize = val;
      this.getData();
    },
    //选取页数
    handleSizeChange(page) {
      this.pageData.page = page;
      this.getData();
    }
  }
};
</script>
<style scoped>
.add {
  margin-left: auto;
  margin-bottom: 10px;
  display: block;
}
</style>
